package com.ydh.company.controller;

import com.ydh.company.dto.ResponseData;
import com.ydh.company.dto.ResultData;
import com.ydh.company.pojo.*;
import com.ydh.company.service.InfoManagementService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;


/**
 * @author: elite
 * @data:2020/4/30 17:53
 * 描述：信息管理，包括公司信息管理 、 个人信息管理
 *   员工信息 、 部门信息
 */
@SuppressWarnings("all")
@RestController
@Api(value = "信息管理接口",tags = "信息管理接口API")
public class InfoManagementController {

    @Autowired
    private InfoManagementService infoManagementService;

    /**
     * 展示公司信息
     * @param client
     * @return
     */
    @PostMapping("/companyInfo/showCompanyInfo")
    @ApiOperation(value = "展示公司信息", notes = "根据客户的登录名查询公司信息并展示", httpMethod = "POST", response = Boolean.class)
    public ResultData showCompanyInfo(
            @RequestBody @ApiParam(name = "client", value = "根据客户的登录名查询公司信息并展示", required = true) Client client) {
            client.setClientCompany("小雷养猪场");
            client.setClientAddress("火星");
            client.setClientName("猪经理");
        return ResponseData.success(client);
    }

    /**
     * 修改公司信息
     * @param client
     * @return
     */
    @PostMapping("/companyInfo/editCompanyInfo")
    @ApiOperation(value = "修改公司信息", notes = "前端传递的修改之后的公司信息", httpMethod = "POST", response = Boolean.class)
    public ResultData editCompanyInfo(
            @RequestBody @ApiParam(name = "client", value = "前端传递的修改之后的公司信息", required = true) Client client) {

        return ResponseData.success("修改成功!");
    }

    /**
     * 展示个人信息
     * @param user
     * @return
     */
    @PostMapping("/personInfo/showPersonInfo")
    @ApiOperation(value = "展示个人信息", notes = "json传递个人登录的账号", httpMethod = "POST", response = ResultData.class)
    public ResultData showPersonInfo(
            @RequestBody @ApiParam(name = "user", value = "个人登录的账号", required = true) User user) {
        User user1 = infoManagementService.showPersonInfo(user);
        return ResponseData.success(user1);
    }

    /**
     *  先根据传递来的个人信息查询相关的部门信息  再更新
     * @param
     * @return
     */
    @PostMapping("/personInfo/editPersonInfo")
    @ApiOperation(value = "编辑个人信息", notes = "json传递用户修改之后的信息", httpMethod = "POST", response = ResultData.class)
    public ResultData editPersonInfo(@ApiParam(name = "username", value = "个人姓名", required = true)String username,
                                     @ApiParam(name = "userAccount", value = "登录时的账号", required = true) String userAccount,
                                     @ApiParam(name = "deptName", value = "部门名称", required = true) String deptName,
                                     @ApiParam(name = "jobName", value = "职位名称", required = true) String jobName,
                                     @ApiParam(name = "tel", value = "联系电话", required = true)String tel
    ) {

        return ResponseData.success("编辑成功");
    }

    /**
     *  先根据传递来的个人信息查询相关的角色job信息 根基job个Auth关联 查询我的权限  再更新
     * @param user
     * @return
     */
    @PostMapping("/personInfo/checkMyAuth")
    @ApiOperation(value = "查看我的权限信息", notes = "json传递个人登录的账号", httpMethod = "POST", response = ResultData.class)
    public ResultData checkMyAuth(
            @RequestBody @ApiParam(name = "user", value = "个人登录的账号", required = true) User user) {
        Auth auth = new Auth();
        auth.setAuthName("想干啥就干啥！");
        return ResponseData.success(auth);
    }

    /**
     * 查看所有员工信息
     * @return
     */
    @PostMapping("/userInfo/checkAll")
    @ApiOperation(value = "查看所有员工信息", notes = "全查不传参数", httpMethod = "POST", response = ResultData.class)
    public ResultData checkAll() {
        List<User> users = new ArrayList<>();
        User user = new User();
        user.setUsername("test01");
        user.setPassword("1111");
        user.setTel("11111111111");
        user.setUserId("1");
        users.add(user);
        User user1 = new User();
        user1.setUsername("test02");
        user1.setPassword("2222");
        user1.setTel("22222222222");
        user1.setUserId("2");
        users.add(user1);
        return ResponseData.success(users);
    }

    /**
     * 新增员工信息
     * @return
     */
    @PostMapping("/userInfo/addUser")
    @ApiOperation(value = "新增员工信息", notes = "json传递的用户信息", httpMethod = "POST", response = ResultData.class)
    public ResultData addUser(
            @RequestBody @ApiParam(name = "user", value = "个人登录的账号", required = true) User user) {
        return ResponseData.success("新增成功");
    }

    /**
     * 修改我的账号信息
     * @return
     */
    @PostMapping("/userInfo/editMyInfo")
    @ApiOperation(value = "修改我的账号信息", notes = "json传递的修改之后的用户信息", httpMethod = "POST", response = ResultData.class)
    public ResultData editMyInfo(
            @RequestBody @ApiParam(name = "user", value = "修改之后的用户信息", required = true) User user) {
        return ResponseData.success("修改成功");
    }


    /**
     *  先根据传递来的角色信息进行权限设置
     * @param job
     * @return
     */
    @PostMapping("/userInfo/editAuthByJob")
    @ApiOperation(value = "权限设置", notes = "json传递的角色信息", httpMethod = "POST", response = ResultData.class)
    public ResultData checkMyAuth(
            @RequestBody @ApiParam(name = "job", value = "角色信息", required = true) Job job) {
        return ResponseData.success("权限设置成功");
    }

    /**
     *  部门信息展示
     *
     * @return
     */
    @PostMapping("/deptInfo/showDeptInfo")
    @ApiOperation(value = "部门信息展示", notes = "全查不需要传参数", httpMethod = "POST", response = ResultData.class)
    public ResultData showDeptInfo() {
        List<Dept> depts = new ArrayList<>();
        Dept dept = new Dept();
        dept.setDeptId("1");
        dept.setDeptLevel(1l);
        dept.setDeptName("劳生部");
        dept.setDeptParentId("1");
        Dept dept1 = new Dept();
        dept1.setDeptId("1");
        dept1.setDeptLevel(2l);
        dept1.setDeptName("劳动卫生部");
        dept1.setDeptParentId("1");
        depts.add(dept);
        depts.add(dept1);
        return ResponseData.success(depts);
    }

    /**
     *  新增部门信息
     *
     * @return
     */
    @PostMapping("/deptInfo/addDept")
    @ApiOperation(value = "新增部门信息", notes = "json传递的新增的部门信息", httpMethod = "POST", response = ResultData.class)
    public ResultData addDept(
            @RequestBody @ApiParam(name = "dept", value = "新增的部门信息", required = true) Dept dept) {
        if (dept.getDeptLevel()==1l) {
            return ResponseData.success("新增主部门成功");
        }else{
            return ResponseData.success("新增主部门失败");
        }

    }


    /**
     *  先根据主部门的名称查询其部门id  然后作为子部们的父级id
     *  新增子部门信息
     *
     * @return
     */
    @PostMapping("/deptInfo/addSonDept")
    @ApiOperation(value = "新增子部门信息", notes = "json传递的新增的部门名称和主部门名称", httpMethod = "POST", response = ResultData.class)
    public ResultData addSonDept(
            @ApiParam(name = "dept_nam", value = "新增的部门名称", required = true) String dept_nam,
            @ApiParam(name = "dept_parent_name", value = "新增的部门所在的主部门名称", required = true) String dept_parent_name) {
       return ResponseData.success("新增子部门成功！");
    }

    /**
     *  先根据主部门的名称查询其部门id  然后作为该部们的父级id
     *  修改部门信息
     *
     * @return
     */
    @PostMapping("/deptInfo/editDept")
    @ApiOperation(value = "修改部门信息", notes = "json传递的修改之后的部门名称和主部门名称", httpMethod = "POST", response = ResultData.class)
    public ResultData editDept(
            @ApiParam(name = "dept_nam", value = "修改之后的部门名称", required = true) String dept_nam,
            @ApiParam(name = "dept_parent_name", value = "修改之后的父级部门名称", required = true) String dept_parent_name) {
        return ResponseData.success("修改部门成功！");
    }

    /**
     *  先根据主部门的名称查询其部门等级 然后根据部门等级进行判断
     *  删除部门
     *
     * @return
     */
    @PostMapping("/deptInfo/delDept")
    @ApiOperation(value = "删除部门信息", notes = "json传递想要删除的部门名称", httpMethod = "POST", response = ResultData.class)
    public ResultData delDept(
            @RequestBody @ApiParam(name = "dept_nam", value = "删除的部门名称", required = true) Dept dept) {
        if (dept.getDeptLevel()==1l) {
            return ResponseData.success("此部门为主部门不能被删除！");
        }else{
            return ResponseData.success("删除部门成功！");
        }
    }

    /**
     *  设置选择员工的角色 并选择它的相关权限
     *
     * @return
     */
    @PostMapping("/editAuthByJob/editAuth")
    @ApiOperation(value = "角色权限设置", notes = "json传递的角色名称和角色所选择的相关权限", httpMethod = "POST", response = ResultData.class)
    public ResultData editAuth(
            @ApiParam(name = "job_name", value = "角色名称", required = true) String job_name,
            @ApiParam(name = "auth_name", value = "角色相关的权限", required = true) String auth_name) {
        return ResponseData.success("角色权限设置成功！");
    }

    /**
     * 条件查询员工信息
     * 选择框的值，输入框的值作为条件进行模糊查询
     * @param condition
     * @return
     */
    @PostMapping("/userInfo/checkUserByCondition")
    @ApiOperation(value = "条件查询员工信息", notes = "前端传递的相关条件selectValue（选择框的值）、inputValue（输入框的值）如：员工姓名，账号，电话等", httpMethod = "POST", response = ResultData.class)
    public ResultData checkUserByCondition(
            @RequestBody @ApiParam(name = "condition", value = "前端传递的相关条件selectValue（选择框的值）、inputValue（输入框的值）如：员工姓名，账号，电话等", required = true) Condition condition,
                         @ApiParam(name = "status", value = "传递的状态码：0 代表启用， 1：代表禁用", required = true)int status) {
        System.out.println("选择框的值："+condition.getSelectValue()+"  输入框的值："+condition.getInputValue());
        List<User> users = new ArrayList<>();
        User user = new User();
        user.setUsername("test01");
        user.setPassword("1111");
        user.setTel("11111111111");
        user.setUserId("1");
        users.add(user);
        User user1 = new User();
        user1.setUsername("test02");
        user1.setPassword("2222");
        user1.setTel("22222222222");
        user1.setUserId("2");
        users.add(user1);
        return ResponseData.success(users);
    }

    /**
     * 修改员工状态
     * @return
     */
    @PostMapping("/userInfo/editUserStatus")
    @ApiOperation(value = "修改员工状态", notes = "改变员工的状态 默认0：代表启用状态 ， 1：代表禁用状态", httpMethod = "POST", response = ResultData.class)
    public ResultData editUserStatus(
            @ApiParam(name = "status", value = "改变员工的状态 默认0：代表启用状态 ， 1：代表禁用状态", required = true) int status) {
        return ResponseData.success("修改成功");
    }

}
